<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>创建投票</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="refresh" content="1200">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/fixedTable/fixed-table.css"/>
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <style>
        .item input {
            border: none;
            width: 100%;
            float: left;
            height: 45px;
            line-height: 45px;
            background: none;
            text-align: center;

        }

        .voteTitle {
            font-size: 10px;
            color: rgb(42, 140, 236);
        }
        }
        .item {
            height: 45px;
            line-height: 45px;
            padding: 0 10px;
            font-size: 14px;
            border-bottom: 1px solid #ddd;
            position: relative;
        }

        .item .title {
        }

        .item .time {
            color: #333;

        }
        .addIcon {
            background: #228bee;
            width: 50px;
            height: 30px;
            margin: 0 auto;
            background-size: cover;
            /* margin-top: 7px; */
            color: #fff;
            font-style: normal;
            text-align: center;
            line-height: 30px;
            font-size: 14px;
            display: inline-block;
            cursor: pointer;
        }
        .openVoteStyle{
            float: right;
            background: rgb(42, 140, 236);
            color: #fff;
            margin-top: 28px;
        }
        .tijiaoBtn {
            /*position: fixed;*/
            display: inline-block;
            margin: auto;
            margin-top: 20px;
            margin-left: 20px;
            left: 47%;
            width: 70px;
            height: 30px;
            line-height: 30px;
            background: #228bee;
            color: #fff;
            text-align: center;
            font-weight: bold;
            font-size: 16px;
            cursor: pointer;
        }
    .tr-h{
        height: 45px;
        margin-top: 5px;
    }
        .voteDesc{
            color: rgb(42, 140, 236);
        }
        .table-detail td.td-value2 {
            padding: 1px !important;
            text-align: left !important;
        }
    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <table class="table-detail" border=0 cellSpacing=0 cellPadding=0 style="width: 100%; table-layout:auto">
        <tbody>
            <tr class="no-print">
                <td colspan="3" class=" no-print td-module " style=" background-color: yellow;">基本信息</td>
            </tr>
            <tr class="no-print">
                <td style="background-color: rgb(245, 243, 243); width: 130px">投票标题</td>
                <td colspan="2" class="td-value" >
                    <div v-if="pageType=='look'||pageType=='shenHe'" class='voteTitle' style="height: 30px;line-height: 30px;color: rgb(42, 140, 236);">{{info.title}}</div>
                    <input v-else type="text" v-model="info.title" class="voteTitle"  id="titleInput" v-on:input="inputInTitle()">
                </td>
            </tr>
            <tr class="no-print">
                <td colspan="3" class=" no-print td-module ">被投票对象</td>
            </tr>
            <tr>
                <td style="background-color: rgb(245, 243, 243); width: 130px">序号</td>
                <td style="background-color: rgb(245, 243, 243);">被投票对象</td>
                <td v-if="pageType!='look'&&pageType!='shenHe'" style="background-color: rgb(245, 243, 243);width:130px;">
                    <input type="button" class="btn oaBtn btn-sm"  @click="addAnswer()" style="margin:auto;cursor: pointer" value="新增" >
                </td>
                <td v-else style="background-color: rgb(245, 243, 243);width:400px;">
                    参投文件
                </td>
            </tr>
            <template v-if="pageType=='look'||pageType=='shenHe'"   v-for="(item,i) in info.voteThemeList">
                <tr v-for="(item2,i2) in item.value" >
                    <td style=" width: 130px" @click="hideYz(i,i2)">{{i2+1}}</td>
                    <td  @click="hideYz(i,i2)">
                        <span  style="text-align: center;color: #2a8cec;" >{{item2.title}}</span>
                    </td>
                    <td  style="padding: 0;width:130px;">
                        <div v-if="item2.attrName" class="fjBox" @click="lookFj(item2.attrUrl)">
                            <div class="fj-tanzhongStyle" >
                                <b :class="fjStyle(item2.attrName)"></b>
                                <div class="name" v-if="item2.attrName" :title="item2.attrName">
                                    {{item2.attrName}}
                                </div>
                                <div class="down"><a href="javascript:void(0)" class="nui-txt-link"
                                                     v-on:click="download(item2.attrUrl,item2.attrName)">下载</a>
                            </div>
                        </div>
                        </div>
                        <div v-else style="color: red;">未上传</div>

                    </td>
                </tr>
            </template>
            <template v-else v-for="(item,i) in info.voteThemeList">
                    <tr v-for="(item2,i2) in item.value">
                        <td>
                            {{i2+1}}
                        </td>
                        <td >
                            <input type="text" v-model="item2.title" class="voteDesc" :placeholder="'被投票对象'+number2big(i2+1)" id="txtCoster"
                                   style="text-align: center;" >
                        </td>
                        <td style="width:130px;">
                            <a style="font-size:small;cursor: pointer; text-align: center;" @click="removeAnswer(i,i2)">删除</a>
                        </td>
                    </tr>
            </template>

            <tr class="no-print">
                <td colspan="3" class=" no-print td-module " style=" background-color: yellow;">参投文件上传截止日期</td>
            </tr>
            <tr>
                <td style="background-color: rgb(245, 243, 243); width: 130px" >参投文件上传截止日期</td>
                <td colspan="2" class="td-title" style="background-color: white;text-align: left">
                    <span v-if="pageType=='look'||pageType=='shenHe'" style="color: rgb(42, 140, 236)" >{{info.uploadTime}}</span>
                    <input v-else  type="text" id="time2"  style="cursor: pointer;color: rgb(42, 140, 236);" v-model="info.uploadTime" @focus="showDatePicker($event)" placeholder="请选择日期">

                    <!--<input v-else  type="text"  style="cursor: pointer" id="utime2" v-model="info.uploadTime" @focus="showDatePicker($event)" placeholder="请选择日期">-->
                </td>
            </tr>

            <tr class="no-print">
                <td colspan="3" class=" no-print td-module " style=" background-color: yellow;">投票截止日期</td>
            </tr>
            <tr>
                <td style="background-color: rgb(245, 243, 243); width: 130px" >投票截止日期</td>
                <td colspan="2" class="td-title" style="background-color: white;text-align: left">
                    <span v-if="pageType=='look'||pageType=='shenHe'" style="color: rgb(42, 140, 236)">{{info.endTime}}</span>
                    <input v-else type="text" id="time"  style="cursor: pointer;color: rgb(42, 140, 236);" v-model="info.endTime " @focus="endDatePicker($event)" placeholder="请选择日期">
                    <!--<input v-else  type="text"  style="cursor: pointer" id="utime" v-model="info.endTime" @focus="endDatePicker($event)" placeholder="请选择日期">-->

                </td>
            </tr>

            <tr class="no-print">
                <td colspan="3" class=" no-print td-module " style=" background-color: yellow;">
                    <span style="margin-left: 80px;">投票人员</span>
                    <!--(pageType=='look'&&info.createUserId==userId)||-->
                   <!-- <template v-if="info.auditFlag!='-1'&&info.createUserId!=userId"><div style="width: 80px;height:3px;float: right;padding-right: 6px;margin-right: 2px;"></div></template>
                    <template v-else-if="info.auditFlag=='-4'"><div style="width: 80px;height:3px;float: right;padding-right: 6px;margin-right: 2px;"></div></template>-->
                    <template v-if="pageType=='add'||pageType=='edit'" >
                        <span style="background-color:white;color:black;float: right;padding-right: 6px;margin-right: 2px;cursor: pointer;text-align: center;font-weight: bold;" @click="gotoUserList()" v-if="info.voteUsers">查看投票人员</span>
                        <div v-else style="width: 80px;height:3px;float: right;padding-right: 6px;margin-right: 2px;"></div>
                    </template>

                    <template v-else><div style="width: 80px;height:3px;float: right;padding-right: 6px;margin-right: 2px;"></div></template>
                </td>
            </tr>
            <tr >
                <td  style="background-color: rgb(245, 243, 243); width: 130px;" >选择投票人员<br><span v-if="info.voteUsers" style="color: #aaa;font-size: 12px;margin: 0;" >(已选择{{info.voteUsers.split(',').length}}人) </span></td>
                <td colspan="2" class="td-title" style="background-color: white">
                    <!--<template  v-if="info.auditFlag!='-1'&&info.createUserId!=userId">
                         <span style="cursor: pointer;color: rgb(42, 140, 236);float: left"
                               @click="gotoUserList()" v-if="info.voteUsers">查看投票人员</span>
                    </template>
                    <template  v-else-if="info.auditFlag=='-4'">
                         <span style="cursor: pointer;color: rgb(42, 140, 236);float: left"
                               @click="gotoUserList()" v-if="info.voteUsers">查看投票人员</span>
                    </template>-->
                    <template v-if="pageType=='add'||pageType=='edit'">
                        <input  v-if="info.voteUsers" type="text"  style="cursor: pointer;color: rgb(42, 140, 236);" @click="gotoTree()" value="修改">
                        <input v-else type="text"  style="cursor: pointer;" @click="gotoTree()" value="选择 ">
                    </template>
                    <template v-else>
                         <span style="cursor: pointer;color: rgb(42, 140, 236);float: left"
                               @click="gotoUserList()" v-if="info.voteUsers">查看投票人员</span>
                    </template>
                </td>
            </tr>

        </tbody>
    </table>
    <table class="table-detail" border=0 cellSpacing=0 cellPadding=0 style="width: 100%; table-layout:auto"  v-if="createAudit&&createAudit.length>0">
        <tbody>
        <tr class="no-print">
            <td colspan="3" class=" no-print td-module " style=" background-color: yellow;">审批进度</td>
        </tr>
        </thead>
    </table>
    <table class="table-detail" style="width: 100%;table-layout: fixed;" v-if="createAudit&&createAudit.length>0">
        <tbody >
        <tr>
            <td class="td-title" style="width: 130px;text-align: center;">审核人</td><td class="td-title" style="width: 130px;text-align: center;">审核状态</td><td class="td-title" style="width: 130px;text-align: center;">审核时间</td><td class="td-title" >审核意见</td>
        </tr>
        <tr v-for="(item,i) in createAudit">

            <td style="text-align: center;">
                <span class="ldName oaColor" style="color: rgb(42, 140, 236)" >{{item.auditorName}}</span>
            </td>
            <td style="text-align: center;">
                <span v-if="item.auditFlag===0" style="color:red">待审核</span>
                <span v-else-if="item.auditFlag===1" class="oaColor" style="color: rgb(42, 140, 236)">已通过</span>
                <span v-else-if="item.auditFlag===2"   class="oaColor" style="color: rgb(42, 140, 236)">已驳回</span>
                <span v-else-if="item.auditFlag===-1"  class="oaColor" style="color: rgb(42, 140, 236)">未提交</span>
            </td>
            <td style="text-align: center;color: rgb(42, 140, 236)" class="oaColor">
                {{formatDate(item.auditTime)}}
            </td>
            <td style="text-align: left;">
                <span style="padding-left: 10px;color: rgb(42, 140, 236)" class="moreSpan oaColor" >{{item.auditAdvise}}</span>
            </td>
        </tr>


        </tbody>
    </table>
    <div style="height:30px;line-height:30px;text-align: center;z-index:999;padding-top:5px;margin-bottom: 15px">
        <template v-if="pageType=='shenHe'">
            <input type="button" value="通过" @click="audit('1')"
                   class="btn oaBtn btn-sm"
                   style="margin-top:5px;">
            <input type="button" value="驳回" @click="audit('2')"
                   class="btn oaBtn btn-sm"
                   style="margin-top:5px;">
        </template>
        <template v-else>
            <input type="button" value="完成" @click="save()" v-if="pageType=='add'"
                   class="btn oaBtn btn-sm"
                   style="margin-top:5px;">
            <input type="button" value="保存" @click="updateInfo()" v-if="pageType=='edit'"
                   class="btn oaBtn btn-sm"
                   style="margin-top:5px;">
            <!--<input type="button" value="保存" @click="updateInfo2()" v-if="pageType=='edit2'"
                   class="btn oaBtn btn-sm"
                   style="margin-top:5px;">-->
            <input type="button" value="返回" @click="returnDt" v-if="pageType=='look'"
                   class="btn oaBtn btn-sm"
                   style="margin-top:5px;">
        </template>

    </div>
    <!--<div style="text-align: center;">
        &lt;!&ndash;<div class="tijiaoBtn" @click="goback()">取消</div>&ndash;&gt;
        <div v-if="pageType=='add'" class="tijiaoBtn" @click="save()">完成</div>
        <div v-if="pageType=='edit'" class="tijiaoBtn" @click="updateInfo()">保存</div>
    </div>-->

</section>


<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=7e54a132"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=558d0414"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>

<script src="https://file.ggxqce.com/web/vue.min.js"></script>

<script type="text/javascript">
    var query = null;
    var app = new Vue({
        el: '#app',
        data: {
            type:'',
            pageType:$.wyui.page.urlParams.pageType,
            mainId:$.wyui.page.urlParams.mainId,
            selectTree:0,
            selectBox:{
                companyList:[],
                departList:[],
                roleList:[],
                selectCompany:[],
                companyNames: [],
                departNames: [],
                roleNames: [],
                companyIds: [],
                userIds:[]
            },
            userModel:false,
            lookUserModel:false,
            lookUserList:[],
            treeObj:"",
            userId: getCurrentUser().id,
            userInfo:{},
            date: "",
            mainInfo:{},
            tabList:[],
            createAudit:[],
            info: {
                createAuditors:[],
                id:$.wyui.page.urlParams.mainId,
                auditors:[],
                auditFlag:"-3",
                auditInfo:"",
                title: "",
                content: "",
                endTime:'',
                uploadTime:'',
                voteUsers:"",
                createUserId:getCurrentUser().id,
                companyId:"",
                createUserName:"",
                voteThemeList: [
                    {
                        "title": "",
                        "value": [
                            { "title": "", "disa":true,"attrUrl":"","attrName":""},
                            { "title": "", "disa": true,"attrUrl":"","attrName":"" },
                            { "title": "", "disa": true,"attrUrl":"","attrName":"" },
                            { "title": "", "disa": true ,"attrUrl":"","attrName":""}
                        ]
                    }
                ]
            },
            isGo:true,
            isOpenBtn:false,

            themeName:""
        },
        methods: {
            formatDate: function (now) {
                if(now){
                    return new Date(now).Format(TimeFormat.middle)
                }
            },
            showDatePicker: function (e) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.info.uploadTime = dp.cal.getNewDateStr();
                        return true;
                    },
                    dateFmt:'yyyy-MM-dd HH:mm'
                });
                $(e.target).blur();
            },
            endDatePicker: function (e) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.info.endTime = dp.cal.getNewDateStr();
                        return true;
                    },
                    dateFmt:'yyyy-MM-dd HH:mm'
                });
                $(e.target).blur();
            },
            inputInTitle:function (e) {
                var that=this;
                if(that.pageType=="add"){
                    if (that.info.title) {
                        that.info.voteThemeList[0].value[0].disa = false;
                    } else {
                        that.info.voteThemeList[0].value[0].disa = true;
                    }
                }

            },
            showModel:function () {
                this.userModel=true;
                var param = {
                    enableNavigateBack: false,
                }
                JSBridge.call(UI, 'setEnableNavigateBack', param)
            },
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            returnDt:function(){
                var pageId = top.getActivePageId('xjtp');
                var $iframe = top.findIframeByName("投票管理");
                $iframe[0].contentWindow.app.getList();
                console.log($iframe[0].contentWindow)
                top.closeTabByPageId(pageId);
            },
            gotoUserList:function(){
                var that=this;

                top.$.dialog({
                    content: 'url:/page/votePc/voteUserList.html?id=' + that.mainId+'&userIds='+that.info.voteUsers,
                    title:"",
                    width: 550,
                    height: 600,
                    max: true,
                    min: true,
                    lock: true
                });
            },
            hideYz:function (index,index2) {
                var that=this;
                if(that.info.title==""){
                    this.info.voteThemeList[index].value[index2].title="";
                    debugger;
                    alert("请先填写投票标题");
                    return false;
                    $("#titleInput").focus();
                }else{
                    var data=this.info.voteThemeList[index]
                    for(b=0;b<index2;b++){
                        if(data.value[b].title==""){
                            this.info.voteThemeList[index].value[index2].title="";
                            alert("请按顺序填写被投票对象")
                            $('#input'+b).focus();
                            return false;
                        }
                    }
                }
            },
            hideTs:function (e,index,index2) {
                var that=this;
                var data=that.info.voteThemeList[index].value[index2].title;
                if(data){
                    if (that.info.voteThemeList[index].value[index2 + 1]){
                        that.info.voteThemeList[index].value[index2 + 1].disa = false;
                    }
                }else{
                    that.info.voteThemeList[index].value[index2+ 1].disa = true;
                }
            },
            removeAnswer:function (index,index2) {
                var that=this;
                if( this.info.voteThemeList[index].value.length<=2){
                   alert("最少保留俩个被投票对象")
                    return false;
                }
                if(this.info.voteThemeList[index].value[index2].title||this.info.voteThemeList[index].value[index2].attrName){
                    top.$.alert({
                        win: this,
                        height: 180,
                        width: 300,
                        icon: '3', //1成功 2失败 3提示 不穿代表无图标
                        title: '确定要删除吗？',
                        blankclose: true,//点击空白是否可关闭
                        ok: "通过",//是否显示确认按钮,
                        okCallback: function (em, opts) {
                            //确认按钮回调
                            that.info.voteThemeList[index].value.splice(index2, 1);
                            em.remove()
                            opts.close && opts.close()
                        },
                        cancel: "取消",
                        cancelCallback: function (em, opts) {
                            em.remove()
                            opts.close && opts.close()
                        }
                    })

                }else{
                    this.info.voteThemeList[index].value.splice(index2, 1);
                }



            },
            addAnswer: function() {
                if(this.info.voteThemeList[0].value.length>=20){
                    JSBridge.call(UI, 'showToast', {title: "最多设置20个被投票对象"})
                    return false;
                }
                var data = this.info.voteThemeList[0];
                var flag = false;
                if (data && data.value.length > 0) {
                    for (b = 0; b < data.value.length; b++) {
                        if (data.value[b].title == "") {
                            this.info.voteThemeList[0].value[b].title = "";
                            flag = true;
                            break;
                        }
                    }
                }
                if (flag) {
                    this.info.voteThemeList[0].value.push({"title": "", "disa": true, "attrUrl": "", "attrName": ""})
                } else {
                    this.info.voteThemeList[0].value.push({"title": "", "disa": false, "attrUrl": "", "attrName": ""})
                }
                //this.info.voteThemeList[0].value.push({ "title": "", "disa": true,"attrUrl":"","attrName":""})

            },
            download: function (attachId, fileName) {
                downloadFile(attachId, fileName)
                return false;
            },
            fjStyle: function (fjName) {
                if (fjName) {
                    var type = fjName.substring(fjName.lastIndexOf('.') + 1);
                    return 'img fj-' + type
                }
                return 'img'
            },
            lookFj:function (url) {
                var that = this
                var param = {
                    url: url,
                }

            },
          /*  uploadFile: function(index,index2) {
                var that = this
                JSBridge.call(FILE, 'uploadFile',{},function (res) {
                    var data = res.sendData;
                    that.info.voteThemeList[index].value[index2].attrUrl=data.url;
                    that.info.voteThemeList[index].value[index2].attrName=data.name;
                })
            },
            deleteFile:function(index,index2) {
                var that=this;
                var param = {
                    title: "提示",
                    content: "确定要删除该附件吗",
                    cancelText: "取消",
                    confirmText: "确定",
                    showCancel: true,
                    cancelable: false
                }
                that.dialogResult = "等待选择..."
                JSBridge.call(UI, 'showDialog', param, function (res) {
                    if ('确定' == res.sendData.data) {
                        that.info.voteThemeList[index].value[index2].attrUrl='';
                        that.info.voteThemeList[index].value[index2].attrName='';
                    } else {

                    }
                })

            },*/
            number2big: function(number) {
                switch (Number(number)) {
                    case 1:
                        return '一';
                        break;
                    case 2:
                        return '二';
                        break;
                    case 3:
                        return '三';
                        break;
                    case 4:
                        return '四';
                        break;
                    case 5:
                        return '五';
                        break;
                    case 6:
                        return '六';
                        break;
                    case 7:
                        return '七';
                        break;
                    case 8:
                        return '八';
                        break;
                    case 9:
                        return '九';
                        break;
                    case 10:
                        return '十';
                        break;
                    case 11:
                        return '十一';
                        break;
                    case 12:
                        return '十二';
                        break;
                    case 13:
                        return '十三';
                        break;
                    case 14:
                        return '十四';
                        break;
                    case 15:
                        return '十五';
                        break;
                    case 16:
                        return '十六';
                        break;
                    case 17:
                        return '十七';
                        break;
                    case 18:
                        return '十八';
                        break;
                    case 19:
                        return '十九';
                        break;
                    case 20:
                        return '二十';
                        break;
                }
            },
            showToast: function (title) {
                var param = {
                    title: title
                }
            },
            save:function(){
                var _this=this;

                if(_this.mainId){


                }else {
                    if (this.isGo) {
                        var time = $("#time").val()
                        var time2 = $("#time2").val()

                        var _this = this;
                        if (this.info.title == "") {
                            alert("请填写投票标题");
                            return false;
                        }
                        for (var i = 0; i < this.info.voteThemeList.length; i++) {
                            var data = this.info.voteThemeList[i]
                            for (b = 0; b < data.value.length; b++) {
                                if (data.value[b].title == "") {
                                    alert("被投票对象不能为空");
                                    return false;
                                }
                            }
                        }
                        if (time2 == "") {
                            alert("请选择参投文件上传截止时间");
                            return false;
                        } else {
                            this.info.uploadTime = time2;
                        }
                        if (time == "") {
                            alert("请选择截止时间");
                            return false;
                        } else {
                            this.info.endTime = time;
                        }

                         if(this.info.voteUsers==""){
                            alert("请选择投票人员");
                            return false;
                        }

                        this.info.companyIds=this.selectBox.companyIds;
                        this.info.roleNames=this.selectBox.roleNames;
                        this.info.departNames=this.selectBox.departNames;

                        this.info.createUserId=this.userInfo.id;
                        this.info.createUserName = this.userInfo.name;
                        this.info.companyId = this.userInfo.companyId;
                        this.isGo =false;
                       /* _this.info.auditors=this.info.auditors;
                        _this.info.createAuditors=this.info.createAuditors;*/
                        console.log(_this.info)
                        $.wyui.postMethod("/vote/saveVote.json", _this.info, function (r) {
                            console.log(_this.info);
                            _this.isGo =true;
                            if(r.id){
                                alert("创建完成")
                                var pageId = top.getActivePageId('xjtp');
                                var $iframe = top.findIframeByName("投票管理");
                                $iframe[0].contentWindow.app.getList();
                                console.log($iframe[0].contentWindow)
                                top.closeTabByPageId(pageId);
                            }else {
                                alert("系统内容异常，请联系IT人员")
                            }
                        });
                    }
                }
            },
            updateInfo:function(){
                if(this.isGo){
                    var _this=this;
                    var time=$("#time").val()
                    var time2=$("#time2").val()


                    if(this.info.title==""){
                        alert("请填写投票标题");
                        return false;
                    }
                    for(var i=0;i<this.info.voteThemeList.length;i++) {
                        var data = this.info.voteThemeList[i]
                        for (b = 0; b < data.value.length; b++) {
                            if (data.value[b].title == "") {
                                alert("被投票对象不能为空");
                                return false;
                            }
                        }
                    }
                    if (time2 == "") {
                        alert("请选择参投文件上传截止时间");
                        return false;
                    } else {
                        _this.info.uploadTime = time2;
                    }
                    if (time == "") {
                        alert("请选择截止时间");
                        return false;
                    } else {
                        _this.info.endTime = time;
                    }

                    if(this.info.voteUsers==""){
                       alert("请选择投票人员");
                        return false;
                    }

                    this.info.companyIds=this.selectBox.companyIds;
                    this.info.roleNames=this.selectBox.roleNames;
                    this.info.departNames=this.selectBox.departNames;

                    this.info.createUserId=this.userInfo.id;
                    this.info.createUserName = this.userInfo.name;
                    this.info.companyId = this.userInfo.companyId;
                    this.isGo=false;
                    var param = {
                        title: "修改中...",
                    }
                    console.log(_this.info);
                    $.wyui.postMethod("/vote/saveVote.json", _this.info, function (r) {
                        _this.isGo=true;
                        if(r.id){
                           alert("修改完成");
                            var pageId = top.getActivePageId('xjtp');
                            var $iframe = top.findIframeByName("投票管理");
                            $iframe[0].contentWindow.app.getList();
                            console.log($iframe[0].contentWindow)
                            top.closeTabByPageId(pageId);


                        }else {
                            alert("系统内容异常，请联系IT人员");
                        }
                    });
                }
            },
            updateInfo2:function(){
                if(this.isGo){
                    var _this=this;
                    this.info.companyIds=this.selectBox.companyIds;
                    this.info.roleNames=this.selectBox.roleNames;
                    this.info.departNames=this.selectBox.departNames;

                    this.info.createUserId=this.userInfo.id;
                    this.info.createUserName = this.userInfo.name;
                    this.info.companyId = this.userInfo.companyId;
                    this.info.auditFlag='-1';
                    this.isGo=false;
                    var param = {
                        title: "修改中...",
                    }
                    console.log(_this.info);
                    $.wyui.postMethod("/vote/saveVote.json", _this.info, function (r) {
                        _this.isGo=true;
                        if(r.id){
                            alert("修改完成");
                            var pageId = top.getActivePageId('xjtp');
                            var $iframe = top.findIframeByName("投票管理");
                            $iframe[0].contentWindow.app.getList();
                            console.log($iframe[0].contentWindow)
                            top.closeTabByPageId(pageId);


                        }else {
                            alert("系统内容异常，请联系IT人员");
                        }
                    });
                }
            },
            gotoTree: function () {
                var that=this;
               /* if(that.pageType=="add"){*/
                    top.$.dialog({
                        content: 'url:/page/votePc/userTree.html?userId=' + getCurrentUser().id + '&mainId=' + that.info.id+'&voteUsers='+that.info.voteUsers+'&companyIds='+that.selectBox.companyIds+'&roleNames='+that.selectBox.roleNames+'&departNames='+that.selectBox.departNames+'&auditFlag='+that.info.auditFlag,
                        title:"选择投票人",
                        width: 500,
                        height: 630,
                        max: true,
                        min: true,
                        lock: true
                    });
               /* }else if(that.pageType=="add"){
                    top.$.dialog({
                        content: 'url:/page/votePc/userTree.html?userId=' + getCurrentUser().id + '&mainId=' + that.info.id+'voteUsers='+that.info.voteUsers+'&companyIds='+that.selectBox.companyIds+'&roleNames='+that.selectBox.roleNames+'&departNames='+that.selectBox.departNames,
                        title:"选择投票人",
                        width: 500,
                        height: 630,
                        max: true,
                        min: true,
                        lock: true
                    });
                }*/

            },
            getAuditors:function () {
                var that=this;
                $.wyui.postMethod('/vote/getAuditList.json', {userId: that.userInfo.id,companyId:that.userInfo.companyId,roleName:that.userInfo.roleName}, function (data) {
                    that.info.auditors= data.auditors;
                    that.info.createAuditors= data.createAuditors;
                    console.log(that.info.createAuditors)
                    if(!data.createAuditors||data.createAuditors.length==0){
                        that.info.auditFlag='-2'
                    }
                })
            },
            getCreateAudit:function () {
                var _this = this; //声明一个变量指向Vue实例this，保证作用域一致
                if(_this.mainId){
                    $.wyui.postMethod("/vote/getMainInfoById.json", {"mainId":_this.mainId}, function (res) {
                        console.log(res)
                        _this.createAudit=res.createAudit;
                    });
                }

            },
            audit: function (type) {
                var that = this;
                if (type == '1') {
                    top.$.alert({
                        win: this,
                        height: 180,
                        width: 300,
                        icon: '3', //1成功 2失败 3提示 不穿代表无图标
                        title: '确定要通过吗？',

                        blankclose: true,//点击空白是否可关闭
                        ok: "通过",//是否显示确认按钮,
                        okCallback: function (em, opts) {
                            //确认按钮回调
                            em.remove()
                            opts.close && opts.close()
                            advise = '同意！';
                            $.wyui.postLoadMethod("/vote/applyCreateAudit.json",{
                                id: that.mainId,
                                auditFlag: 1,
                                advise: '同意!',
                                userId: that.userInfo.id,
                            }, function (r) {
                                console.log(r)
                                var pageId = top.getActivePageId('xjtp');
                                var $iframe = top.findIframeByName("投票管理");
                                $iframe[0].contentWindow.app.getList();
                                console.log($iframe[0].contentWindow)
                                top.closeTabByPageId(pageId);
                            }, false, false)
                        },
                        cancel: "取消",
                        cancelCallback: function (em, opts) {
                            em.remove()
                            opts.close && opts.close()
                        }
                    })
                } else {
                    that.copierReturn();
                    return;
                }
            },

            copierReturn: function () {
                var that = this;
                $.dialog({
                    content: 'url:/page/votePc/returnReason.html?mainId=' + that.mainId + "&t=" + new Date(),
                    title: '填写驳回原因',
                    width: 300,
                    height: 200,
                    max: false,
                    min: false,
                    lock: true
                });
            }
            ,

        },
        mounted:function () {
            var that = this; //声明一个变量指向Vue实例this，保证作用域一致
            that.userId=getCurrentUser().id
            /*$.wyui.postMethod("/vote/getUserInfoByUserId.json", {id:that.userId}, function (info) {
                that.userInfo=info.userInfo;
                that.getAuditors();
                console.log(that.userInfo)
            });*/
            $.wyui.postMethod(urlConfig.system.user.getUserViewById,{id:that.userId}, function (info) {
                that.userInfo=info;
                console.log(that.userInfo)
            });
            that.getCreateAudit();
            if(that.pageType=='edit'||that.pageType=='look'||that.pageType=='shenHe'){
                that.info.voteThemeList[0].value=[];
                $.wyui.postMethod("/vote/getVoteDetail.json", {id:that.mainId}, function (info) {
                    console.log(info);
                    that.info.title=info.main.title;
                    that.info.endTime=info.main.endTime;
                    that.info.uploadTime=info.main.uploadTime;
                    that.info.voteUsers=info.main.voteUsers;
                    that.info.createUserId=info.main.createUserId;
                    that.selectBox.companyIds=info.main.companyIds;
                    that.selectBox.departNames=info.main.departNames;
                    that.selectBox.roleNames=info.main.roleNames;

                    console.log(that.info.createUserId+that.userId)
                    for(var i=0;i<info.main.voteThemeList[0].desc.length;i++){
                        var data = info.main.voteThemeList[0].desc[i];
                        that.info.voteThemeList[0].value.push(
                            { "title": data.description, "disa":false,"attrUrl":data.attrUrl,"attrName":data.attrName}
                        )
                    }
                    console.log(that.info.voteThemeList)
                });
            }

            /*if(that.mainId){
                $.wyui.postMethod("/vote/getThemeList.json", {"mainId":that.mainId,"tel":that.userInfo.tel,"userId":that.userId}, function (res) {
                    var result=res.result;
                    var $body = $('body');
                    document.title = res.main.title;
                    var $iframe = $('<iframe src="/dist/img/icon.png"></iframe>');
                    $iframe.on('load',function() {
                        setTimeout(function() {
                            $iframe.off('load').remove();
                        }, 0);
                    }).appendTo($body);

                    that.mainInfo=res.main;


                    if(res.main.auditFlag=='-4'){
                        console.log(res.result)
                        that.info.voteThemeList[0].value=[];
                        for(var i=0;i<res.result[0].optionList.length;i++){
                            var data=res.result[0].optionList[i];
                            that.info.voteThemeList[0].value.push(
                                { "title": data.description, "disa":false,"attrUrl":"","attrName":""}
                            )
                        }
                        setTimeout(function () {
                            $("#time2").val(res.main.uploadTime);
                            $("#time").val(res.main.endTime);
                        },300)
                        console.log( $("#time2"))
                        that.info.id=res.main.id;
                        that.info.title=res.main.title;
                        that.info.endTime=res.main.endTime;
                        that.info.uploadTime=res.main.uploadTime;

                    }


                  /!*  that.getCreateAudit();*!/

                    /!*that.info.voteUsers=res.main.voteUsers;
                    that.selectBox.companyIds=res.main.companyIds.split(',')
                    that.getCompanyList();
                    that.selectBox.departNames=res.main.departNames.split(',')
                    that.selectBox.roleNames=res.main.roleNames.split(',')

                    if( that.treeObj.getNodesByFilter){

                        that.treeObj.getNodesByFilter(function (node) {
                            if(res.main.voteUsers.indexOf(node.id)>-1) {
                                that.treeObj.checkNode(node, true, true, false);
                            }else{
                                that.treeObj.checkNode(node, false, false, false);
                            }
                        });
                    }else{


                        console.log("网不好 延迟加载")
                        setTimeout(function () {
                            that.treeObj.getNodesByFilter(function (node) {
                                if(res.main.voteUsers.indexOf(node.id)>-1) {
                                    that.treeObj.checkNode(node, true, true, false);
                                }else{
                                    that.treeObj.checkNode(node, false, false, false);
                                }
                            });
                        },3000)
                    }*!/


                    if(result&&result.length>0){
                        that.tabList=result[0].optionList;
                        var isOpenBtn=true;
                        for(var b=0;b<result[0].optionList.length;b++){

                            if(result[0].optionList[b].attrUrl==''){
                                isOpenBtn=false;
                            }
                        }
                        that.isOpenBtn=isOpenBtn;
                    }

                });
            }else{
                that.hideLoading()
                that.getCompanyList();
            }*/
        }
    });

</script>

<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        page: {
            urlParams: null,
            queryParams: {
                requestPage: 1,
                pageSize: 30
            },
            dataUrl: '',
            createQueryParams: function () {
            },
            getByPage: function (type) {
                $.ajax({
                    url: $.wyui.page.dataUrl,
                    data: JSON.stringify($.wyui.page.queryParams),
                    beforeSend: function () {

                    },
                    complete: function () {
                    },
                    success: function (r) {
                        $.wyui.page.queryParams.requestPage++;

                        if (r.data.sendData.pager && r.data.sendData.pager.pageCount == 0) {
                            r.data.sendData.pager.pageCount = 1;
                        }
                        if (type == "scroll") {
                            $.wyui.page.getByPage_scroll_callback(r.data.sendData.records);
                        } else {
                            if ($.wyui.page.getByPage_callback_new) {
                                $.wyui.page.getByPage_callback_new(r.data.sendData.records);
                            }
                        }

                    }
                });
            }
        },
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>
</body>
</html>